package com.x.erp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.erp.model.InsuranceContract;
import com.x.erp.rpc.InsuranceContractRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 延保合同Controller
 *
 * @author pansong
 */
@RestController
@RequestMapping(value = "/insuranceContract")
public class InsuranceContractController extends BaseController {

	@Reference
	private InsuranceContractRpcService insuranceContractRpcService;

	/**
	 * 延保商品订单审核通过
	 *
	 * @param insuranceContract
	 * @return
	 */
	@RequestMapping(value = "/insertInsuranceContract", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel insertInsuranceContract(InsuranceContract insuranceContract, String orderId) {
		if (StringUtils.isEmpty(orderId)) {
			return new ResultModel(ResultCode.RESULT_FAIL, "订单Id不能为空");
		}
		if (StringUtils.isEmpty(insuranceContract.getUserId())) {
			return new ResultModel(ResultCode.RESULT_FAIL, "用户Id不能为空");
		}
		// 调用接口，更改订单状态，并生成合同
		insuranceContract = insuranceContractRpcService.insertInsuranceContract(insuranceContract, orderId);
		return new ResultModel(ResultCode.RESULT_SUCCESS, "添加成功", insuranceContract);
	}
}
